package com.sl.au.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.servlet.ModelAndView;

import com.sl.au.entity.BusinesssellerBaseInfo;
import com.sl.au.entity.Evaluate;
import com.sl.au.entity.Role;
import com.sl.au.service.EvaluateService;
import com.sl.au.service.BusinesssellerBaseInfoService;
import com.sl.au.service.OptionService;
import com.sl.au.service.RoleService;
@RestController
@RequestMapping(value = "/ui/evaluate")
public class EvaluateController extends BaseController{

	@Autowired
	private BusinesssellerBaseInfoService businesssellerBaseInfoService;
	@Autowired
	private EvaluateService evaluateService;
    @Autowired
    private OptionService optionService;
    @Autowired
    private RoleService roleService;
    
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView index(ModelAndView modelAndView, HttpServletRequest request) {

			modelAndView=this.createLayoutView("evaluate/evaluateindex");
		return modelAndView;
	}
	
	@RequestMapping(value = "getevaluateinfopage", method = RequestMethod.GET)
	public Map<String, Object> getevaluateinfopage(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		int start = Integer.parseInt(request.getParameter("start"));
		int length = Integer.parseInt(request.getParameter("length"));
		String key=request.getParameter("key");
		Role role = roleService.getRepository().findByName("商户");
		List<Evaluate> evaluate = this.evaluateService.getPage(start, length, key,role.getId(), "createTime", Sort.Direction.DESC);
		int count = evaluateService.getCount(key,role.getId());
		map.put("data", evaluate);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}
}
